package com.ruoyi.web.controller.fantasy;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.fantasy.domain.FantasyItemType;
import com.ruoyi.fantasy.service.IFantasyItemtypeService;
import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyCompletionCondition;
import com.ruoyi.fantasy.service.IFantasyCompletionConditionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 完成条件 信息操作处理
 * 
 * @author wanghui
 * @date 2019-07-05
 */
@Controller
@RequestMapping("/fantasy/fantasyCompletionCondition")
public class FantasyCompletionConditionController extends BaseController
{
    private String prefix = "fantasy/fantasyCompletionCondition";
	
	@Autowired
	private IFantasyCompletionConditionService fantasyCompletionConditionService;

	@Autowired
	private IFantasyItemtypeService fantasyItemtypeService;

	@RequiresPermissions("fantasy:fantasyCompletionCondition:view")
	@GetMapping()
	public String fantasyCompletionCondition()
	{
	    return prefix + "/fantasyCompletionCondition";
	}
	
	/**
	 * 查询完成条件列表
	 */
	@RequiresPermissions("fantasy:fantasyCompletionCondition:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FantasyCompletionCondition fantasyCompletionCondition)
	{
		startPage();
        List<FantasyCompletionCondition> list = fantasyCompletionConditionService.selectFantasyCompletionConditionList(fantasyCompletionCondition);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出完成条件列表
	 */
	@RequiresPermissions("fantasy:fantasyCompletionCondition:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyCompletionCondition fantasyCompletionCondition)
    {
    	List<FantasyCompletionCondition> list = fantasyCompletionConditionService.selectFantasyCompletionConditionList(fantasyCompletionCondition);
        ExcelUtil<FantasyCompletionCondition> util = new ExcelUtil<FantasyCompletionCondition>(FantasyCompletionCondition.class);
        return util.exportExcel(list, "fantasyCompletionCondition");
    }
	
	/**
	 * 新增完成条件
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		List<FantasyItemType> fantasyItemTypeList = fantasyItemtypeService.selectFantasyItemtypeList(null);
		mmap.put("fantasyItemTypeList", fantasyItemTypeList);
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存完成条件
	 */
	@RequiresPermissions("fantasy:fantasyCompletionCondition:add")
	@Log(title = "完成条件", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FantasyCompletionCondition fantasyCompletionCondition)
	{
		fantasyCompletionCondition.setId(String.valueOf(IdWorker.nextId()));
		fantasyCompletionCondition.setCreateBy(ShiroUtils.getLoginName());
		fantasyCompletionCondition.setCreateTime(new Date());
		return toAjax(fantasyCompletionConditionService.insertFantasyCompletionCondition(fantasyCompletionCondition));
	}

	/**
	 * 修改完成条件
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		FantasyCompletionCondition fantasyCompletionCondition = fantasyCompletionConditionService.selectFantasyCompletionConditionById(id);
		mmap.put("fantasyCompletionCondition", fantasyCompletionCondition);
		List<FantasyItemType> fantasyItemTypeList = fantasyItemtypeService.selectFantasyItemtypeList(null);
		mmap.put("fantasyItemTypeList", fantasyItemTypeList);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存完成条件
	 */
	@RequiresPermissions("fantasy:fantasyCompletionCondition:edit")
	@Log(title = "完成条件", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FantasyCompletionCondition fantasyCompletionCondition)
	{
		fantasyCompletionCondition.setUpdateBy(ShiroUtils.getLoginName());
		fantasyCompletionCondition.setUpdateTime(new Date());
		return toAjax(fantasyCompletionConditionService.updateFantasyCompletionCondition(fantasyCompletionCondition));
	}
	
	/**
	 * 删除完成条件
	 */
	@RequiresPermissions("fantasy:fantasyCompletionCondition:remove")
	@Log(title = "完成条件", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(fantasyCompletionConditionService.deleteFantasyCompletionConditionByIds(ids));
	}
	
}
